package com.itcam.controller;

//3.演示接收请求参数

import com.itcam.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

//3.演示获取请求参数

@RestController
@RequestMapping("/hello03")
public class Hello03Controller {

    //http://localhost:8080/hello03/h01?uname=jim&hobby=football&hobby=basketball&hobby=pingpong&address=China
    @GetMapping("/h01")
    public String h01(String uname , String[] hobby , String address){
        //String request.getParameter("uname")
        //String[] request.getParameterValues("hobby")
        System.out.println("uname = " + uname);
        System.out.println(Arrays.toString(hobby));
        System.out.println("address = " + address);

        return "succ" ;
    }

    //http://localhost:8080/hello03/h02?uname=jim&address=China
    @GetMapping("/h02")
    public String h02(@RequestParam("uname") String username , String address){
        System.out.println("username = " + username);
        System.out.println("address = " + address);
        return "succ" ;
    }

    //http://localhost:8080/hello03/h03?uname=jim&address=China
    @GetMapping("/h03")
    public String h03(User user){
        System.out.println("user = " + user);
        return "succ" ;
    }

    //http://localhost:8080/hello03/h04?uname=jim&hobby=football&hobby=basketball&hobby=pingpong&address=China
    @GetMapping("/h04")
    public String h04(String uname ,@RequestParam List<String> hobby , String address){
        System.out.println("uname = " + uname);
        System.out.println("hobby = " + hobby);
        System.out.println("address = " + address);

        return "succ" ;
    }




}
